<template>
    <view class="xilu">
		<view>
        <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
            <view class="container plr30 pt30">
                <view class="flex-box pb40" v-for="(item,index) in userLists">
                    <image :src="item.avatar" mode="aspectFill" class="xilu_avatar"></image>
                    <view class="flex-grow-1">
                        <view class="fs32 blue pb20">{{item.nickname}}</view>
                        <view class="fs24 col5">粉丝数：{{item.fans_count}}</view>
                    </view>
                    <view class="btn1" @click="toggleFocus(index,item.id)" v-if="!item.is_focus_count">+ 关注</view>
                    <view class="btn3" @click="toggleFocus(index,item.id)" v-else>互关</view>
                </view>
            </view>
        </mescroll-body>
		</view>
    </view>
</template>

<script>
    // 引入mescroll-mixins.js
    import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
    export default {
        mixins: [MescrollMixin], // 使用mixin
        data() {
            return {
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				userLists:[]
            };
        },
        methods: {
            /*上拉加载的回调*/
            upCallback(page) {
            	// 此处可以继续请求其他接口
            	let pageNum = page.num; // 页码, 默认从1开始
            	let pageSize = page.size; // 页长, 默认每页10条
            	this.$core.get({url: 'xilumarket.forum/user_fans',loading:false,data:{page: pageNum,pageSize:pageSize},success: (ret) => {
            			let data = ret.data;
            			// 接口返回的当前页数据列表 (数组)
            			let curPageData = data.data;
            			// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
            			let curPageLen = curPageData.length;
            			// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
            			let totalPage = data.last_page;
            	
            			//设置列表数据
            			if (page.num == 1) this.userLists = []; //如果是第一页需手动置空列表
            			this.userLists = this.userLists.concat(curPageData); //追加新数据
            	
            			// 请求成功,隐藏加载状态
            			//方法一(推荐): 后台接口有返回列表的总页数 totalPage
            			this.mescroll.endByPage(curPageLen, totalPage);
            	
            			
            			setTimeout(() => {
            				this.mescroll.endSuccess(curPageLen)
            			}, 20)
            		},
            		fail: () => {
            			//  请求失败,隐藏加载状态
            			this.mescroll.endErr()
            		}
            	})
            		
            },
            // 关注取关
            toggleFocus(index,userId) {
                this.$core.post({
                    url: 'xilumarket.forum/toggle_focus',
                    data: {
                        user_id: userId
                    },
                    success: ret => {
                        this.userLists[index].is_focus_count = ret.data.is_focus_count;
                        //this.$forceUpdate();
                    },
                    fail: err => {
                        console.log(err);
                    }
                });
            },
		}
    }
</script>

<style lang="scss" scoped>
    .xilu {
        &_avatar {
            width: 100rpx;
            height: 100rpx;
            border-radius: 50%;
            margin-right: 30rpx;
        }

        .btn1 {
            height: 56rpx;
            line-height: 56rpx;
            width: 110rpx;
        }
        .container{
            min-height: auto;
            height: auto;
        }
    }
</style>
